package com.vulb.bean;

import java.util.Calendar;
import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName="session")
public class Session implements Parcelable {
    @DatabaseField
    protected int uid;
    @DatabaseField
    protected String sessionid;
    @DatabaseField
    protected long loginTime;
    @DatabaseField
    protected String account;
    @DatabaseField
    protected String pwd;
    
    public Session()
    {}
    public Session(int uid,String sessionid,Calendar loginTime,String account,String pwd)
    {
    	this.uid = uid;
    	this.sessionid = sessionid;
    	this.loginTime = loginTime.getTime().getTime();
    	this.account = account;
    	this.pwd = pwd;
    }
    
    public int getUid() 
    {
        return uid;
    }
    public void setUid(int uid) 
    {
        this.uid = uid;
    }
    
    public String getSessionid() 
    {
        return sessionid;
    }
    public void setSessionid(String sessionid) 
    {
        this.sessionid = sessionid;
    }
    
    public Calendar getLoginTime() {
    	Calendar c = Calendar.getInstance();
    	c.setTimeInMillis(loginTime);
        return c;
    }
    public void setLoginTime(Calendar loginTime) 
    {
        this.loginTime = loginTime.getTime().getTime();
    }
    
    public String getAccont()
    {
    	return account;
    }
    public void setAccont(String account)
    {
    	this.account = account;
    }
    
    public String getpwd()
    {
    	return pwd;
    }
    public void setpwd(String pwd)
    {
    	this.pwd = pwd;
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }
    
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(uid);
        dest.writeString(sessionid);
        dest.writeLong(loginTime);
        dest.writeString(account);
        dest.writeString(pwd);
    }
    
    public static final Parcelable.Creator<Session> CREATOR = new Parcelable.Creator<Session>() 
    {
        @Override
        public Session createFromParcel(Parcel source) {
        	Calendar c = Calendar.getInstance();
        	c.setTime(new Date(source.readLong()));
            Session s = new Session(source.readInt(),source.readString(),c,source.readString(),source.readString());
            return s;
        }

        @Override
        public Session[] newArray(int size) {
            return new Session[size];
        }
    };
}